package com.ray.controller;

import com.ray.bean.CompanyMaterialTableBean;
import com.ray.bean.DatatablesViewPageBean;
import com.ray.bean.QCResultMain;
import com.ray.bean.WarehouseInOutDetailBean;
import com.ray.exception.ServiceException;
import com.ray.service.MaterialTypeCheckTypeService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("materialCheckType")
public class MaterialTypeCheckTypeController {
    @Autowired
    MaterialTypeCheckTypeService materialTypeCheckTypeService;
    @Autowired
    HttpServletRequest request;


    //获取公司设置的检验类型
    @RequestMapping("/getCheckType")
    @ResponseBody
    public Map getCheckType() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.getCheckType(map));
    }


    //修改检验类型
    @RequestMapping("/updateCheckType")
    @ResponseBody
    public Map updateCheckType() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.updateCheckType(map));
    }

    //设置公司的检验类型
    @RequestMapping("/setCheckType")
    @ResponseBody
    public Map setCheckType() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.setCheckType(map));
    }

    //获取物料设置的检验类型
    @RequestMapping("/getMaterialCheckType")
    @ResponseBody
    public Map getMaterialCheckType() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.getMaterialCheckType(map));
    }

    //设置物料检验类型
    @RequestMapping("/setMaterialCheckType")
    @ResponseBody
    public Map setMaterialCheckType() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.setMaterialCheckType(map));
    }


    //查找需要qc的物料
    @RequestMapping("/getNeedQcMaterial")
    @ResponseBody
    public DatatablesViewPageBean<CompanyMaterialTableBean> getNeedQcMaterial() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return materialTypeCheckTypeService.getNeedQcMaterial(map);
    }

    //设置qc结果
    @RequestMapping("/setQcResult")
    @ResponseBody
    public Map setQcResult() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.setQcResult(map));
    }

    //获取qc结果
    @RequestMapping("/getQcResult")
    @ResponseBody
    public DatatablesViewPageBean<QCResultMain> getQcResult() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return materialTypeCheckTypeService.getQcResult(map);
    }


    //审核qc
    @RequestMapping("/approvalQcResult")
    @ResponseBody
    public Map approvalQcResult() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.approvalQcResult(map));
    }

    //根据检测编号获取检测详情
    @RequestMapping("/getDetailByCheckReportNo")
    @ResponseBody
    public Map getDetailByCheckReportNo() throws ServiceException, CloneNotSupportedException{
        Map map=RequestUtil.getRequestAllParam(request);
        Assert.isTrue(map.get("checkReportNo")!=null&&!"".equals(map.get("checkReportNo")),"为获取到检验编号");
        return ResponseUtil.ResponseResult(materialTypeCheckTypeService.getDetailByCheckReportNo(map));
    }

}
